home *** CD-ROM | disk | FTP | other *** search
/ Video Toaster 4.0 / Video Toaster v4.0.iso / arexx / editor / haiku.rexx < prev    next >
OS/2 REXX Batch file  |  1995-03-06  |  11KB  |  357 lines

  1. /* A haiku generator CMD: Haiku                           */
  2. /* from "Using ARexx on the Amiga" by Sullivan and Zamara */
  3. /* CGized By Bob C.                                       */
  4. /* Adapted By Arnie                                       */
  5. /* Encrufted by Robert                                    */
  6. /* Tue Dec  1 22:45:53 1992                               */
  7.  
  8. call addlib('PROJECT_REXX_PORT' , 0)
  9.  
  10. call InitVocab()
  11. call random(,,time('s'))
  12.  
  13. do while GenHaiku()=1
  14.    end
  15.  
  16. call req_tell("Canceled!")
  17. call remlib('PROJECT_REXX_PORT')
  18. exit
  19.  
  20.  
  21. /* GenHaiku
  22.  
  23.    Generate and return a single Haiku poem
  24. */
  25. GenHaiku:
  26.    /* Select a template, parse it into 3 lines, and clear output buffer. */
  27.    t = random(1,num_templates)
  28.    parse var tem.t line.1 '+' line.2 '+' line.3
  29.    out. = ''
  30.  
  31.    /* Process template lines one at a time. */
  32.    do i=1 to 3
  33.  
  34.       /* Keep going till template line exhausted. */
  35.       do while length(line.i) > 0
  36.          parse var line.i cmd 3 qual 4 line.i
  37.  
  38.          c = left(cmd, 1)
  39.          ucmd = upper(cmd)
  40.  
  41.          if v.ucmd ~= "" then do
  42.             w = word(v.ucmd, random(1, words(v.ucmd)))
  43.  
  44.             if datatype(c, 'u') then
  45.                w = upper(left(w, 1))substr(w, 2)
  46.  
  47.             upper c
  48.  
  49.             if c='V' & qual='@' then
  50.                w = add_ing(w)
  51.             else if c='N' & qual='s' then
  52.                w = pluralize(w)
  53.             else
  54.                line.i = qual || line.i
  55.  
  56.             end
  57.          else if c='/' then do
  58.             parse value cmd || qual || line.i with '/' list '/' line.i
  59.             w = word(list, random(1, words(list)))
  60.             end
  61.          else
  62.             parse value cmd || qual || line.i with w 2 line.i
  63.  
  64.          out.i = out.i || w
  65.          end
  66.       end
  67.       out.1=translate(out.1,' ','_')
  68.       out.2=translate(out.2,' ','_')
  69.       out.3=translate(out.3,' ','_')
  70.       return req_tell("Editor Haiku 4.0",out.1,out.2,out.3)
  71.  
  72.  
  73.  
  74. /* Add_Ing
  75.  
  76.    Add the `ing' suffix to the given verb. The trick here is to double
  77.    the final consonant of the verb in many but not all instances. The
  78.    exception list and the code that employs take care of this. When new
  79.    verbs are added to the vocabulary lists, consider whether the `ing'
  80.    form is exceptional.
  81. */
  82. add_ing: procedure
  83.  
  84.    exc. = 0
  85.    exc.withdraw = 1
  86.    exc.wander  = 1
  87.    exc.snarf   =1
  88.    exc.wallow  = 1
  89.    exc.flicker = 1
  90.    exc.shiver  = 1
  91.    exc.wonder  = 1
  92.    exc.edit  = 1
  93.    exc.render  = 1
  94.    exc.pay  = 1
  95.    exc.eat  = 1
  96.    exc.walk = 1
  97.    exc.shoot = 1
  98.    exc.fling = 1
  99.    exc.speak = 1
  100.    exc.flow = 1
  101.    exc.crawl = 1
  102.    exc.creep = 1
  103.    exc.reek = 1
  104.    exc.sink = 1
  105.    exc.croak = 1
  106.    exc.burn = 1
  107.    exc.stink = 1
  108.    exc.steal = 1
  109.    exc.peel = 1
  110.    exc.kill = 1
  111.    exc.toast = 1
  112.    exc.rent = 1
  113.    exc.drink = 1
  114.    exc.Smooth = 1
  115.    exc.Load = 1
  116.    exc.Stretch = 1
  117.    exc.Clear = 1
  118.    exc.Patch = 1
  119.    exc.Morph = 1
  120.    exc.destroy = 1
  121.    exc.accept = 1
  122.    exc.reboot = 1
  123.    exc.despair = 1
  124.    exc.descend = 1
  125.    exc.command = 1
  126.    exc.broadcast = 1
  127.    exc.shiver = 1
  128.    exc.Jitter = 1
  129.    exc.Mirror = 1
  130.    exc.Bevel = 1
  131.    exc.Align = 1
  132.    exc.encruft = 1
  133.    exc.command = 1
  134.    exc.splatter = 1
  135.    exv  = upper(arg(1))
  136.  
  137.    parse value arg(1) with 100 -3 l3 +1 l2 +1 l1
  138.  
  139.    if index("mbgprndlt",l1)>0 & index("aeiou",l2)>0 & index("aeiou",l3)=0 then do
  140.       if ~exc.exv then
  141.          w = arg(1) || l1
  142.       else
  143.          w = arg(1)
  144.       end
  145.    else if l1='e' then
  146.       w = left(arg(1), length(arg(1)) - 1)
  147.    else
  148.       w = arg(1)
  149.  
  150.    return w || 'ing'
  151.  
  152.  
  153. /* Pluralize
  154.  
  155.    Pluralize the given word, taking account of certain exceptions. If you
  156.    add nouns to the vocabulary lists, consider whether the pluralization
  157.    is exceptional.
  158. */
  159. pluralize: procedure expose v.
  160.  
  161.    exc. = 0
  162.    exc.ice  = 1
  163.    exc.beach   = 1
  164.    exc.spooge  = 1
  165.    exc.kluge  = 1
  166.    exc.mouse   = 1
  167.    exc.moose   = 1
  168.    exc.bass    = 1
  169.    exc.box     = 1
  170.    exc.peach   = 1
  171.    exc.glance  = 1
  172.    exc.bus     = 1
  173.    exc.juice   = 1
  174.    exc.paintbox = 2
  175.    exc.Image   = 2
  176.    exc.Sequence = 2
  177.    exc.lotus   = 2
  178.    exc.gecko   = 10
  179.    exc.cry     = 11
  180.    exc.dei     = 12
  181.  
  182.    w  = arg(1)
  183.    uw = upper(w)
  184.  
  185.    /* Nouns with an exception code of 1 or 2 have 1 or 2 syllables
  186.       respectively in the singular, but an extra syllable in the plural.
  187.       Since the syllables must remain constant, we replace such a noun
  188.       with another from its list, until we find one that is not lengthened
  189.       by pluralization.
  190.    */
  191.    do while exc.uw > 0 & exc.uw < 10
  192.       list = value('v.n'exc.uw)
  193.       w    = word(list, random(1, words(list)))
  194.       uw   = upper(w)
  195.       end
  196.  
  197.    /* Match capitalization of argument word with (possibly) new word. */
  198.    if datatype(left(arg(1),1),'u') then
  199.       w = upper(left(w,1))substr(w,2)
  200.  
  201.    /* Pluralize */
  202.    select
  203.       when exc.uw =  0 then w = w || 's'
  204.       when exc.uw = 10 then w = w || 'es'
  205.       when exc.uw = 11 then w = left(w,2) || 'es'
  206.       otherwise
  207.          call inform("Invalid pluralize exception" exc.uw)
  208.          exit
  209.       end
  210.  
  211.    return w
  212.  
  213.  
  214. InitVocab:
  215.  
  216. v. = ""
  217.  
  218. /* Adjectives, one syllable */
  219. av.a1 = "quick wild small hot white wet blue pink old light dark"
  220. v.a1 = v.a1 "sad deep lost free drunk slow dumb hard soft damp dry"
  221. v.a1 = v.a1 "tight loose gross cold clean proud dead plaid munged nuked"
  222. v.a1 = v.a1 "strong weak young dull ill mean flat sharp kluged tweaked"
  223. v.a1 = v.a1 "wudge freak"
  224.  
  225. /* Adjectives, two syllables */
  226. v.a2 = "evil putrid empty crooked runny fallen dismal crufty"
  227. v.a2 = v.a2 "potent rabid gnarly golden hairy wrinkled cuspy"
  228. v.a2 = v.a2 "robust rancid smiling toasted paisley dying measly"
  229. v.a2 = v.a2 "brain_dead stupid plastic bogus lo-res frothy 3D hi-res"
  230. v.a2 = v.a2 "opaque diffuse default wireframe print-res angry flattened"
  231.  
  232. /* Nouns, one syllables */
  233. v.n1 = "goat moose cat stream kluge fade mouse sprite bomb bass disc box"
  234. v.n1 = v.n1 "worm hack moon dog glance flame spooge cow pig shell cone Fudd"
  235. v.n1 = v.n1 "frob Spam curve spline clone duck sea hand fish neck growth ice"
  236. v.n1 = v.n1 "point sync deck cop food RAM wine beer car bus bike juice ball"
  237. v.n1 = v.n1 "box light scene key bone frame fog sky ground view stat Duff"
  238.  
  239. /* Nouns, two syllables */
  240. v.n2 = "shadow forest guitar keyboard missile toaster teapot pointer guru"
  241. v.n2 = v.n2 "ooblick chomper dissolve parrot budgie info volume red_head"
  242. v.n2 = v.n2 "CD valley switcher cookie framestore farmer hard_disk wetware"
  243. v.n2 = v.n2 "Toaster LightWave model object cheese_shop option splitter"
  244. v.n2 = v.n2 "CG starship airport sports_car pudding oatmeal layout weasel wirehead"
  245. v.n2 = v.n2 "image preview shadow bump_map color segment motion widget"
  246. v.n2 = v.n2 "lens_flare spot_light backdrop zenith nadir program hacker"
  247. v.n2 = v.n2 "Flyer Screamer Rapter"
  248.  
  249. /* Verbs, one syllable */
  250. v.v1 = "walk eat grab shoot fling frag stick speak flow live cut paste"
  251. v.v1 = v.v1 "rip crawl creep reek bite sink take croak burn stop stink flip"
  252. v.v1 = v.v1 "spit shine steal fade peel crave kill stab writhe split"
  253. v.v1 = v.v1 "dub toast tape cut rent burn shop chomp pay drink eat snore"
  254. v.v1 = v.v1 "make smooth load save clear lathe blast ride"
  255. v.v1 = v.v1 "clone skin morph grok mung phreak count nuke snarf"
  256.  
  257. /* Verbs, two syllables */
  258. v.v2 = "explode desire adlib destroy decline accept dissolve endure reboot"
  259. v.v2 = v.v2 "rebel retire despair encode wonder bubble flicker grumble"
  260. v.v2 = v.v2 "decode descend compile command render edit broadcast shiver wallow"
  261. v.v2 = v.v2 "jitter combine copy bevel rotate splatter command withdraw"
  262. v.v2 = v.v2 "align extrude mirror flatline encruft guru"
  263.  
  264. /* Verbs, one syllable, transitive */
  265. v.v3 = "eat grab shoot cut rip bite sink take burn stop flip steal peel crave"
  266. v.v3 = v.v3 "stab split scream toast chomp drink save blast ride clone mung"
  267. v.v3 = v.v3 "snarf nuke kill find own lose keep know see smell hear taste feel"
  268.  
  269. /* Verbs, one syllable, transitive, past tense */
  270. v.t1 = "ate killed shot cut bit sank burned stopped stole found lost smashed"
  271. v.t1 = v.t1 "chomped drank munged nuked snarfed took boned"
  272.  
  273. /* Prepositions, one syllable */
  274. v.p1 = "on of in near past at by in through from"
  275.  
  276. /* Prepositions, two syllables */
  277. v.p2 = "left_of upon under beside over west_of beyond above below around"
  278. v.p2 = v.p2 "inside outside next_to far_from behind"
  279.  
  280. /* Relative adverbs, one syllable */
  281. v.r1 = "where when while as"
  282.  
  283. /* Little words that can precede nouns, biased towards `the' */
  284. v.l1 = "the God's Hell's this my Bob's your his her the Ken's Ron's Moe's"
  285. v.l1 = v.l1 "Skell's Mark's Paul's Tim's James' Dawn's Penn's its our the Wil's"
  286. v.l1 = v.l1 "Kirk's Spock's Worf's Q's Croooow's Joel's Bart's  Dreux's"
  287. v.l1 = v.l1 "Death's Jud's Dan's Dick's some all Ren's Charles' Anne's Steve's"
  288. v.l1 = v.l1 "Grue's Chuck's Gregs's Chris's Todd's Simba's Nala's Brad's"
  289. v.l1 = v.l1 "Greg's Grue's Bob's Lloyd's"
  290.  
  291. /* Names, two syllables */
  292. v.h2 = "Robert NewTek Pink_Floyd Tami Smithers Billy Flanders Londo"
  293. v.h2 = v.h2 "David Yoko Arnie Satan Jesus Homer Kerri Barney"
  294. v.h2 = v.h2 "Ervin Batman Robin Mofo some_jerk James_Bond"
  295. v.h2 = v.h2 "Kiki Simone Lobo Ayn_Rand John_Cleese Elvis Allen"
  296. v.h2 = v.h2 "Peter Kenbe Junior Daniel Teller Kristy Kelly Stuart"
  297. v.h2 = v.h2 "Dana Picard Riker Data Geordi Crusher Milhouse Apu Laura Tammy"
  298. v.h2 = v.h2 "Cambot Gypsy Alex Bobbi Lisa Maggie Porter Stephen Mojo Stimpy"
  299. v.h2 = v.h2 "JoJo Jason"
  300.  
  301. /* Haiku templates
  302.  
  303.    The special tokens in the templates are:
  304.  
  305.    a1,n2 etc.     Part of speech, replaced randomly from corresponding list
  306.    A1,N2 etc.     Same, but with initial capital
  307.    +              Converted to linefeed
  308.    @              After verb, specifies conversion to `ing' (gerund) form
  309.    s              After noun, specifies conversion to plural form
  310.    /wordlist.../  Replaced by a word picked randomly from the list
  311.  
  312.    All other symbols in the templates are taken literally.
  313. */
  314. tem.  = ""
  315. tem.1 = "A1 n1, a2 n1.+L1 a1, a2 n2 v1s.+A1 n1, a1 n2."
  316. tem.2 = "P2 the a1 n1,+R1 the a2 n2 v1s,+I v1; the n1 v1s."
  317. tem.3 = "The a1 n1 v1@;+It is the a2 n2.+V2@, I v1."
  318. tem.4 = "The a2 n1 v1s+R1 a2 n2s v2.+Does the a1 n1 v1?"
  319. tem.5 = "Not a1, but a2,+H2 comes to the n2.+L1 a1 n2 v1s."
  320. tem.6 = "A1, a2, a2,+H2 v1s. H2 v2s,+V2@, v1@."
  321. tem.7 = "/Never Sometimes/ a1, but a1,+H2 knows /no my some all/ a1 n2s.+A2, /he she/ v2s."
  322. tem.8 = "/Not Quite/ a1, /and but or/ a2,+H2 comes to the n2.+L1 a1 n2 v1s."
  323. tem.9 = "A1 n1, a2 n1.+L1 a1, a2 n2 v1s.+A1 n1, a1 n2."
  324. tem.10 = "The a2 n1 v1s +R1 a2 n2s v2.+Does the a1 n1 v1?"
  325. tem.11 = "Not a1, but a2,+H2 comes to the n2.+L1 a1 n2 v1s."
  326. tem.12 = "A1, a2, a2,+H2 v1s. H2 v2s,+V2@, v1@."
  327. tem.13 = "Hey! Get back to work +You lazy, no good n2. +The world is v1@!"
  328. tem.14 = "If n2s could v1, +And v3 l1 n2 today, +The n1 would v3 you."
  329. tem.15 = "If n2s could v1, +And v3 l1 n2 today, +The n1 would v3 you."
  330. tem.16 = "As the n1 draws near, +H2 v3s our n1. You must +V3 the a1 n2."
  331. tem.17 = "Alone the a1 n1 v1s. +'Where is my n2?', you ask. +/Ack! Doh! Oops!/ H2 t1 it."
  332. tem.18 = "Attention all n1s! +When v1@ n2s v2, +It's time to v2."
  333.  
  334. do i=1 while tem.i ~= ""
  335.    end
  336.  
  337. num_templates = i - 1
  338.  
  339. return
  340.  
  341. syntax:
  342. error:
  343.         t=REQ_TELL('Rexx Script Error')
  344.         exit
  345.  
  346.  
  347. page_is_blank:
  348.   page_size=GET_PAGE(SIZE)
  349.   line_size=GET_LINE(SIZE)
  350.   if (page_size = 0 | page_size = 1) & line_size = 0 then
  351.      return 1
  352.   else
  353.      return 0
  354.  
  355.  
  356.  
  357.